home *** CD-ROM | disk | FTP | other *** search
- Path: mail2news.demon.co.uk!genesis.demon.co.uk
- From: Lawrence Kirby <fred@genesis.demon.co.uk>
- Newsgroups: comp.lang.c
- Subject: Re: Basic Question on SWITCH
- Date: Sun, 04 Feb 96 13:36:03 GMT
- Organization: none
- Message-ID: <823440963snz@genesis.demon.co.uk>
- References: <4e4cu4$95f@vixen.cso.uiuc.edu> <4e8p6m$n8q@ns.RezoNet.NET> <TANMOY.96Jan26162346@qcd.lanl.gov> <4ehfuj$166g@ns.RezoNet.NET>
- Reply-To: fred@genesis.demon.co.uk
- X-NNTP-Posting-Host: genesis.demon.co.uk
- X-Newsreader: Demon Internet Simple News v1.27
- X-Mail2News-Path: genesis.demon.co.uk
-
- In article <4ehfuj$166g@ns.RezoNet.NET> ray@ultimate-tech.com "Ray Dunn" writes:
-
- >In referenced article, Tanmoy Bhattacharya says...
- >>
- >>In article <3108ED49.987@cmt.lpr.mail.carel.fi> Ari Lukumies
- >><aril@cmt.lpr.mail.carel.fi> writes:
- >><snip>
- >> if (strchr("0123456789", a))
- >> ... /* It was a digit, do something */
- >>
- >>A special case for digits:
- >>
- >>if ((unsigned)(a-'0')<10)
-
- That's better written as:
-
- if ((unsigned)a-'0'<10)
-
- >> /* It _is_ a digit, do something */
- >>
- >>But then what is wrong with isdigit?
-
- As a curiosity:
-
- #define isdigit(ch) ((unsigned)+(ch)-'0'<10)
-
- is a portable definition of isdigit.
-
- >Indeed. In the general case there is no guarantee that all the digits
- >are consecutive as they are in ASCII, so the use of isdigit is the only
- >portable way to go, although the strchr example works fine too, if
- >slowly.
-
- As others have noted the standard makes these guarantees for digits.
-
- >[As a matter of interest, MS 'C' uses a character table with bits
- >defining all the various character types. isdigit etc. uses this
- >table. MS provides profiling functions which allows the customization
- >of this table]
-
- There are a number of aspects of the is*() functions which the standard
- makes locale-specific. However none of these apply to isdigit() which is
- not locale specific. Changing the 'is a digit' bits in the table is likely
- to mess up a lot of software that depends on them (and that probably includes
- the standard library). So maybe there is a use for as isdigit type macro
- defined as above.
-
- --
- -----------------------------------------
- Lawrence Kirby | fred@genesis.demon.co.uk
- Wilts, England | 70734.126@compuserve.com
- -----------------------------------------
-